package org.smile.db.sql.page;


public class RowNumberDialectPage implements DialectPage {

	private String sql;
	
	public RowNumberDialectPage(String sql){
		this.sql=sql;
	}
	public String getCountSql() {
		return "SELECT COUNT(*) FROM ("+sql+") COUNT_TABLE_T";
	}
	
	public String getDataSql(int page,int size) {
		int firstRow=(page-1)*size;
		int endRow=firstRow+size;
		return "SELECT * FROM (SELECT DATA_TABLE_T.*,ROW_NUMBER() OVER () ROW_NUM FROM ("+sql+") DATA_TABLE_T) RESULT_TABLE_T WHERE ROW_NUM>"+firstRow+" AND ROW_NUM<="+endRow;
	}

}
